/*******************************************************************************
 * Copyright (c) 2014 Francesco Gabbrielli.
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v2.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *     Francesco Gabbrielli - initial API and implementation
 ******************************************************************************/
package it.francescogabbrielli.android.solidalapp.home;

import it.francescogabbrielli.android.solidalapp.AppStatus;
import it.francescogabbrielli.android.solidalapp.BaseActivity;
import it.francescogabbrielli.android.solidalapp.BaseFragment;
import it.francescogabbrielli.android.solidalapp.DataEvent;
import it.francescogabbrielli.android.solidalapp.R;
import it.francescogabbrielli.android.solidalapp.R.id;
import it.francescogabbrielli.android.solidalapp.R.layout;
import it.francescogabbrielli.android.solidalapp.StatusEvent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

/**
 * 
 */
public class DebugFragment extends BaseFragment<HomeFragmentListener> {

	public DebugFragment() {
		
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		return inflater.inflate(R.layout.fragment_debug, container, false);
	}	
	
	@Override
	public void onStatusUpdate(StatusEvent event) {
		
		BaseActivity ba = (BaseActivity) getActivity();
		AppStatus s = ba.getApp().getStatus();
		
//		String device = s.getDevice()!=null ? s.getDevice().getString("information") : ""; 
		
		new AsyncTask<String, Integer, String>() {
			
			private TextView tv;

			@Override
			protected String doInBackground(String... params) {
			    View v = getView();
				tv = (TextView) v.findViewById(R.id.text_hello);
				String ret = 
						"Connection: " + params[0]
						+ "\nGCM: " + params[1]
						+ "\nInfo: "+params[2]
						+ "\nLocation: "+params[3]
				;
				return ret;
			}
			
			@Override
			protected void onPostExecute(String result) {
				tv.setText(result);
			};
			
		}.execute(
			String.valueOf(s.getNetworkStatus()), 
			s.getGcmId(),
			"",
			String.valueOf(s.getLocation())
		);
	}

	
	@Override
	public void onDataChanged(DataEvent event) {
		// TODO Auto-generated method stub
	}
}
